package com.mango.Tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    @SuppressWarnings("static-access")
    public static Long dateToLong(String timeStr) {
        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
        Long time = null;
//        System.out.println("将要转换为时间的字符串" + timeStr);
        try {
            time = sp.parse(timeStr).getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            time = new Date().getTime();
            System.out.println("时间转换出错辣");
        }
        return time;
    }

    public static String localDateFormat(Long time) {
        String timeStr = null;
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        timeStr = sf.format(new Date(time));
        return timeStr;
    }

    public static Long getDatePoor(Date endDate, Date nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
//        long hour = diff % nd / nh;
        // 计算差多少分钟
//        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day;
    }

    public static Long getDatePoor(String sendDate, String snowDate)  {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Date endDate = null;
        try {
            endDate = sf.parse(sendDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date nowDate = null;
        try {
            nowDate = sf.parse(snowDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long nd = 1000 * 24 * 60 * 60;
//        long nh = 1000 * 60 * 60;
//        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
//        long hour = diff % nd / nh;
        // 计算差多少分钟
//        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
//        return day + "天" + hour + "小时" + min + "分钟";
        return day;
    }

}
